﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Tb.App.API.Applications.Command.Cultivation;
using Tb.App.Domain.Rabbit.Cultivation;
using Tb.App.ErrorCode;

namespace Tb.App.API.Controllers.Rabbit
{
    /// <summary>
    /// 养殖信息-控制器API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CultivationController : ControllerBase
    {
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<CultivationController> logger;
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="logger">日志</param>
        /// <param name="mediator">中介者</param>
        public CultivationController(ILogger<CultivationController> logger,IMediator mediator)
        {
            this.logger = logger;
            this.mediator = mediator;
        }
        #region 养殖信息
        /// <summary>
        /// 添加养殖基本信息
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回添加任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddCultivation(AddCultivationCommand request)
        {
            try
            {
                logger.LogInformation("-添加养殖基本信息操作日志-");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);

                throw;
            }
        }
        /// <summary>
        /// 养殖信息查询
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回查询命令</returns>
        [HttpGet]
        public Task<ApiResult<CultivationModel>> GetCultivationQuery([FromQuery]GetCultivationQueryCommand request)
        {
            try
            {
                logger.LogInformation("-养殖信息查询操作日志-");
                return mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);

                throw;
            }
        }
        #endregion
        #region 免疫信息
        /// <summary>
        /// 添加养殖免疫信息(动态行)
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddImmunity(AddImmunityCommon request)
        {
            try
            {
                logger.LogInformation("-添加养殖免疫信息(动态行)操作日志-");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);

                throw;
            }
        }
        /// <summary>
        /// 免疫信息查询
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回查询任务</returns>
        [HttpGet]
        public Task<ApiResult<List<ImmunityModel>>> GetImmunityQuery([FromQuery]GetImmunityQueryCommond request)
        {
            try
            {
                logger.LogInformation("-免疫信息查询操作日志-");
                return mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);

                throw;
            }
        }
        /// <summary>
        /// 修改养殖免疫信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdImmunity(UpdImmunityCommand request)
        {
            try
            {
                logger.LogInformation("-修改养殖免疫信息操作日志-");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);

                throw;
            }
        }
        /// <summary>
        /// 删除养殖免疫信息
        /// </summary>
        /// <param name="Id">编号</param>
        /// <returns>返回删除任务</returns>
        [HttpDelete]
        public async Task<ApiResult<int>> Delimmunity(int Id)
        {
            try
            {
                logger.LogInformation("-删除养殖免疫信息操作日志-");
                DelimmunityCommand command = new DelimmunityCommand
                {
                    Id = Id
                };
                return await mediator.Send(command);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);

                throw;
            }
        }
        #endregion
        #region 养殖企业信息
        /// <summary>
        /// 添加养殖企业信息
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回添加任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddCultivationCommpany(AddCultivationCommpanyCommand request)
        {
            try
            {
                logger.LogInformation("-添加养殖企业信息操作日志-");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);

                throw;
            }
        }
        /// <summary>
        /// 养殖企业信息查询
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回查询任务</returns>
        [HttpGet]
        public async Task<ApiResult<CultivationCommpanyModel>> GetCultivationCommpany([FromQuery]GetCultivationCommpanyCommand request)
        {
            try
            {
                logger.LogInformation("-养殖企业信息查询操作日志-");
                return await mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("=>" + ex.Message);

                throw;
            }
        }
        #endregion

    }
}
